package shiyan4;

import java.io.IOException;
import java.net.*;

public class Server {
    public static void main(String[] args) {
        String group = "239.1.2.3";
        int port = 8080;

        try (DatagramSocket socket = new DatagramSocket()) {
            for (int i = 1; i < 6; i++) {
                String msg="这是第"+i+"条数据";
                byte[] buf = msg.getBytes();
                InetAddress address = InetAddress.getByName(group);
                DatagramPacket packet = new DatagramPacket(buf, buf.length, address, port);
                socket.send(packet);
                System.out.println("已发送"+msg);
            }
            System.out.println("发送完成");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
